package com.zlx.taskcenter.consumer.Impl;

import com.alibaba.fastjson.JSON;
import com.zlx.redismessage.constant.RedisQueue;
import com.zlx.redismessage.model.User;
import com.zlx.redismessage.task.DetectionTask;
import com.zlx.redismessage.util.RedisUtils;
import com.zlx.taskcenter.annotations.Consumer;
import com.zlx.taskcenter.consumer.BaseConsumer;

/**
 * @author gaoYuan
 * @version 2.7、3.0
 * @description 数据检测消费者
 * @date 2022-5-11
 */
@Consumer(queue = RedisQueue.DZZZ)
public class Detection extends BaseConsumer {

    @Override
    public void onMessage(String message) throws Exception {
        User user = JSON.parseObject(message, User.class);
        String id = user.getId();
        user.getAddress();
        user.getFlag();
		user.getName();
		logger.info("=========================" + Thread.currentThread().getId() + Thread.currentThread().getName() + "=====================================");
		logger.info(user.toString());
		logger.info("=========================|||||||||||||||||||||||||=====================================");
		Thread.sleep(1000);
    }

    @Override
    public void onError(String msg, Exception e) {
        // 在这里处理onMessage中抛出的异常...
        logger.error("处理任务发生异常...");
        logger.error(e.getMessage());
        User User = JSON.parseObject(msg, User.class);
        String logId = User.getId();
        String key = DetectionTask.REDIS_PREFIX + logId;
        RedisUtils.incremental(key, "error", 1L);
    }
}
